package ontology.concepts.vo;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.ElementCollection;
import javax.persistence.Embeddable;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;

import org.hibernate.annotations.IndexColumn;

import jade.content.Concept;

@Entity
public class Consequent implements Concept{
	
	@Id
	@GeneratedValue
	private int consequentId;
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	private Set<VOObligation> prescription = new HashSet<VOObligation>();
	
	
	public Set<VOObligation> getPrescription() {
		return prescription;
	}

	public void setPrescription(Set<VOObligation> prescription) {
		this.prescription = prescription;
	}

	public int getConsequentId() {
		return consequentId;
	}

	public void setConsequentId(int consequentId) {
		this.consequentId = consequentId;
	}

	
	@Override
	public String toString() {
		return "Consequent [consequentId=" + consequentId + ", prescription="
				+ prescription.toString() + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + consequentId;
		result = prime * result
				+ ((prescription == null) ? 0 : prescription.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Consequent other = (Consequent) obj;
		if (consequentId != other.consequentId)
			return false;
		if (prescription == null) {
			if (other.prescription != null)
				return false;
		} else if (!prescription.equals(other.prescription))
			return false;
		return true;
	}
	
	@Override
	public Consequent clone(){
		Consequent cons = new Consequent();
		cons.setConsequentId(consequentId);
		HashSet<VOObligation> obligations = new HashSet<VOObligation>();
		for (VOObligation voObligation : getPrescription()) {
			obligations.add(voObligation.clone());
		}
		cons.setPrescription(obligations);
		return cons;
	}

}
